import { defineStore } from 'pinia';
import { reqHospitalDepartment, reqHospitalDetail } from '@/api/hospital';
// 引入详情的ts类型
import type { DetailState } from './interface/index';
import type { HospitalDetail, HosPitalDetail, DeparmentResponseData } from '@/api/hospital/type';

const useDetailStore = defineStore('Detail', {
  state: (): DetailState => {
    return {
      // 医院详情
      hospitalInfo: ({} as HosPitalDetail),
      // 科室
      departmentInfo: [],
    }
  },
  actions: {
    // 获取医院详情
    async getHospital(hoscode: string) {
      let res: HospitalDetail = await reqHospitalDetail(hoscode)
      if (res.code == 200) {
        this.hospitalInfo = res.data;
      }
    },
    // 获取医院科室
    async getDepartment(hoscode: string) {
      let res: DeparmentResponseData = await reqHospitalDepartment(hoscode)
      if (res.code == 200) {
        this.departmentInfo = res.data
      }
    }
  },
  getters: {

  }
})

export default useDetailStore;